import socket

# 1.创建socket对象
sk = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 3.传输数据
while True:
    msg = input("请输入你的数据>>>")
    sk.sendto(msg.encode('utf-8'),("127.0.0.1", 5000))

    if not msg:
        continue
    if msg == 'q':
        break

    # 4.接收服务端发送的数据
    serData, addr = sk.recvfrom(1024)
    print(serData.decode("utf-8"))

# 5.关闭连接【客户端必须写】
sk.close()